package dao

import (
	"onerk4/yk/common/global"
	"onerk4/yk/common/model"
)

func QueryUserByUsername(username string) (result model.User, err error) {
	err = global.DB.Model(&model.User{}).Where("username = ?", username).Limit(1).Find(&result).Error
	return
}

func AddCourse(m *model.Course) (err error) {
	err = global.DB.Create(m).Error
	return
}

func QueryCourseList() (result []model.Course, err error) {
	err = global.DB.Model(&model.Course{}).Find(&result).Error
	return
}

func QueryCourseInfoById(id int64) (result model.Course, err error) {
	err = global.DB.Model(&model.Course{}).Where("id = ?", id).Limit(1).Find(&result).Error
	return
}

func UpdateCourse(id int64, c model.Course) (err error) {
	err = global.DB.Model(&model.Course{}).Where("id = ?", id).Updates(&c).Error
	return
}

func AddCoursePanic(m *model.CoursePanic) (err error) {
	err = global.DB.Create(m).Error
	return
}

func QueryCourseInfo(id int64) (result model.CoursePanic, err error) {
	err = global.DB.Model(&model.CoursePanic{}).Where("course_id = ?", id).Limit(1).Find(&result).Error
	return
}

func AddOrder(m *model.Order) (err error) {
	err = global.DB.Create(m).Error
	return
}
